package com.cci.kangdao.dao;


import com.cci.kangdao.dto.request.SaveCampaignTaskRequest;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.mybatis.spring.annotation.MapperScan;

import java.util.List;
import java.util.Map;

/**
 * campaign任务类dao
 *
 */
@MapperScan
public interface CampaignTaskInfoDao {

	int insertBatch(@Param("workOrderId")Long workOrderId, @Param("campaignTasks")List<SaveCampaignTaskRequest.CampaignTask> campaignTasks,@Param("userId")Long userId,@Param("createTime") String createTime);

	@Update("update CampaignTaskInfo_T set Flag = -1,Deleter = #{userId},DeleteTime = #{deleteTime} where WorkOrderId = #{workOrderId} and CampaignRangeId = #{campaignRangeId} and Flag = 0")
	int delTaskByOrderIdRangeId(@Param("workOrderId")Long workOrderId,@Param("campaignRangeId")String campaignRangeId,@Param("userId")Long userId,@Param("deleteTime") String deleteTime);

	@Select("select ID as id,WorkOrderId as workOrderId,TrpCode as trpCode,TrpName as trpName,TrpDescription as trpDescription,CampaignRangeId as campaignRangeId,OldCampaignTaskId as oldCampaignTaskId,\n" +
			"NewCampaignTaskId as newCampaignTaskId ,CampaignTaskStatus as campaignTaskStatus ,Esn as esn ,Gsn as gsn ,RefusalReasonValue as refusalReasonValue,\n" +
			"RefusalOtherReason as refusalOtherReason ,UnfinishedReasonValue as unfinishedReasonValue ,UnfinishedOtherReason as unfinishedOtherReason,TrpFile trpFile \n" +
			"from CampaignTaskInfo_T \n" +
			"where WorkOrderId = #{workOrderId} and Flag = 0")
	List<Map<String,Object>> getCampaignListByOrderId(@Param("workOrderId")Long workOrderId);

	int updateCampaignTaskInfo(Map<String, Object> map);

	int updateInfo(Map<String, Object> map);

	@Update("update CampaignTaskInfo_T set CampaignTaskStatus = #{campaignTaskStatus},Updator = #{updator},UpdateTime = #{updateTime} where WorkOrderId = #{workOrderId} and Flag = 0")
	int updateCampaignTaskStatus(@Param("campaignTaskStatus")Integer campaignTaskStatus,@Param("updator")Long updator,
								 @Param("updateTime")String updateTime,@Param("workOrderId")Long workOrderId);
}
